<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <div id="test">
    FirstName: <input type="text" v-model="firstName"><br>
    LastName: <input type="text" v-model="lastName"><br>
    
    <p>fullName3(计算属性): {{fullName3}}</p>
    <br>
    <p>fullName4(监视): {{fullName4}}</p>
  </div>

  <script src="../js/vue.js"></script>
  <script>
    const vm = new Vue({
      el: "#test",
      data: {
        firstName:'A',
        lastName:'B',
        fullName4:'A-B'
      },
      computed:{
        fullName3(){
            setTimeout(()=>{
                return this.firstName+'*'+this.lastName
            },1000)
        }
      },
      watch:{
        firstName:{
            handler:function(newValue,oldValue){
                setTimeout(()=>{
                    return this.fullName4 = newValue+'*'+this.lastName
                },1000)
            }
        }
      }
    })
    vm.$watch('lastName',function(newValue,oldValue){
        setTimeout(()=>{
            return this.fullName4 = this.firstName+'*'+newValue
        },1000)
    })
  </script>
</body>
</html>